package com.example.yangbo.abc;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.LinkedList;

/**
 * Created by yangbo on 2017/7/16.
 */

public class TestListViewAdapter extends BaseAdapter {

    private LinkedList<TestListViewModel> dataSourceOfList;
    private Context mContext;

    public void setDataSourceOfList(LinkedList<TestListViewModel> dataSourceOfList) {
        this.dataSourceOfList = dataSourceOfList;
    }
    public void setmContext(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public int getCount() {
        return dataSourceOfList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_testlistview, viewGroup, false);
        }

        ImageView headerImg = (ImageView) view.findViewById(R.id.headerimage);
        TextView titleTV = (TextView) view.findViewById(R.id.titleTv);
        TextView contentTV = (TextView) view.findViewById(R.id.contentTv);

        headerImg.setBackgroundResource(dataSourceOfList.get(i).getHeaderImgId());
        titleTV.setText(dataSourceOfList.get(i).getTitle());
        contentTV.setText(dataSourceOfList.get(i).getContent());

        return view;
    }
}
